package application.view 
{
	import away3d.containers.ObjectContainer3D;
	import away3d.materials.BitmapMaterial;
	import away3d.primitives.Plane;
	import awayphysics.collision.shapes.AWPStaticPlaneShape;
	import awayphysics.dynamics.AWPRigidBody;
	import core.Size;
	import flash.geom.Matrix3D;
	import flash.geom.Vector3D;
	
	/**
	 * ...
	 * @author Tiago Salomon
	 */
	public class FloorView extends ObjectContainer3D 
	{
		private var _obj :Plane;
		
		public function FloorView() 
		{	
			this._obj = new Plane(new BitmapMaterial(new floor()), Size.CUBE, Size.CUBE, 1, 1);
			this._obj.material.bothSides = true;
			this._obj.rotationX = 90;
			
			this.addChild(_obj);			
			
			var groundShape : AWPStaticPlaneShape = new AWPStaticPlaneShape(new Vector3D(0, 0, -1));
				
			var groundRigidbody : AWPRigidBody = new AWPRigidBody(groundShape, _obj, 0);
				groundRigidbody.activate();

			var impulse : Vector3D = new Vector3D(this.x, this.y, this.z);
				impulse.normalize();
				impulse.scaleBy(200000);
				
			groundRigidbody.applyCentralImpulse(impulse);
			
			SceneHolder.physicsWorld.addRigidBody(groundRigidbody);
			
			var rot : Matrix3D = new Matrix3D();
				rot.appendRotation(90, new Vector3D(1, 0, 0));
			groundRigidbody.rotation = rot;
			
		}
		
	}

}